import request from '@/utils/request'
import NodeRSA from 'node-rsa'

export function login(username, password) {
  const keyData = '-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCCU+sOs2dwS5k10e44LhAwEVDicF2SM9O6/cDdXuDyemjx/RMT/yDJHQ4+jqJOB11nIdeo2lvrD/9oPMePauTjCaXd7AxO75Gzx24skFOb6Rw5Tvjffgsm0ka+/UbK6OWdruPXJDSCrnRskQVhMNRrV6qGLaOCWCQzNwOcz7aCMQIDAQAB-----END PUBLIC KEY-----'
  const key = new NodeRSA(keyData)
  const time = new Date().getTime()
  key.setOptions({ encryptionScheme: 'pkcs1' })
  const encrypted = key.encrypt(time + password, 'base64')
  const data = {
    account: username,
    credentials: encrypted,
    loginTime: time,
    verifyType: 1

  }
  return request({
    url: '/agencyManager/agency/identity/login',
    method: 'post',
    data
  })
}

export function getInfo(token) {
  return request({
    url: '/agencyManager/agency/employess/get',
    method: 'get'
  })
}

export function logout() {
  return request({
    url: '/agencyManager/agency/identity/logout',
    method: 'get'
  })
}

export function getAgencyName(id) {
  return request({
    url: `/mgrService/agencyService/getAgencyNameAndCode/${id}`,
    method: 'get',
  })
}

